/*
 * @Author: ziqi jhzq12345678
 * @Date: 2024-08-19 17:08:20
 * @LastEditors: ziqi jhzq12345678
 * @LastEditTime: 2025-01-17 15:39:22
 * @FilePath: /pornhub_app/lib/src/modules/search/search_hotword.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import 'package:pornhub_app/http/http_service.dart';

import 'package:pornhub_app/views/search/search_controller.dart';
import 'package:pornhub_app/routes/routes.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class SearchHotWord extends StatefulWidget {
  const SearchHotWord({
    super.key,
  });

  @override
  State<SearchHotWord> createState() => _SearchHotWord();
}

class _SearchHotWord extends State<SearchHotWord> {
  List videotags = [];
  final searchvc = Get.find<SearchPageController>();
  Future fetchAllTags(int mark) async {
    final r = await httpInstance.get(
      url: '/video/hot/list',
    );

    if (!mounted) return;

    if (r['data'] != null) {
      setState(() {
        videotags = r['data'];
      });
    }
  }

  @override
  void initState() {
    super.initState();
    fetchAllTags(1);
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          alignment: Alignment.centerLeft,
          margin: EdgeInsets.only(top: 20.w, bottom: 14.w),
          child: Text(
            '大家都在搜',
            style: TextStyle(
              color: COLOR.hexColor('#ffffff'),
              fontSize: 14.w,
            ),
          ),
        ),
        Wrap(
          spacing: 12.w,
          runSpacing: 20.w,
          alignment: WrapAlignment.start,
          children: videotags
              .map((e) => GestureDetector(
                    onTap: () {
                      final word = e['hotTitle'];
                      searchvc.addHistory(word);
                      Get.toNamed(Routes.searchresult, arguments: {
                        'word': word,
                      });
                    },
                    child: Container(
                      padding:
                          EdgeInsets.symmetric(horizontal: 14.w, vertical: 5.w),
                      decoration: BoxDecoration(
                          color: COLOR.hexColor('#423765'),
                          borderRadius: BorderRadius.circular(13.5.w)),
                      child: Text(
                        e['hotTitle'],
                        style: TextStyle(
                            color: COLOR.playerThemColor, fontSize: 12.w),
                      ),
                    ),
                  ))
              .toList(),
        )
      ],
    );
  }
}
